package com.gingko.duominuo.utils

import android.app.Activity
import android.content.Context
import android.view.View
import android.view.WindowManager



/**
 * 设置添加屏幕的背景透明度  1,：全透明；0.5：半透明  0~1，取自己想到的透明度
 *
 * @param bgAlpha
 */
fun backgroundAlpha(mContext: Context, bgAlpha: Float) {
    val lp = (mContext as Activity).window.attributes
    //0.0-1.0
    lp.alpha = bgAlpha
    mContext.window.attributes = lp
    if (bgAlpha < 1f) {
        mContext.window.addFlags(
            WindowManager.LayoutParams.FLAG_DIM_BEHIND
        )
    } else {
        mContext.window.clearFlags(
            WindowManager.LayoutParams.FLAG_DIM_BEHIND
        )
    }
}